package com.apobates.jforum2.troll.nest.service;

import com.apobates.jforum2.troll.forum.stub.vo.BoardGroupCollectVo;
import com.apobates.jforum2.troll.forum.stub.vo.BoardGroupVo;
import com.apobates.jforum2.troll.nest.FrontFeignClientConfig;
import com.apobates.jforum2.troll.nest.service.BoardGroupClient.BoardGroupClientFallback;
import com.apobates.jforum2.troll.nest.service.BoardGroupClient.BoardGroupFallbackFactory;
import java.util.Collections;
import java.util.List;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 版块组(卷)服务客户端
 * @author xiaofanku
 * @since 20210413
 */
@FeignClient(value="TROLL-GATEWAY",
            contextId="boardGroupClient",
            fallbackFactory=BoardGroupFallbackFactory.class,
            configuration = FrontFeignClientConfig.class
)
@RequestMapping(value="/boardgroup")
public interface BoardGroupClient {
    //1:指定的版块组
    @GetMapping("/{volume}")
    ResponseEntity<BoardGroupVo> get(@PathVariable("volume")int boardGroupId);
    
    //2:指定版块组的图标
    @GetMapping("/{volume}/ico/{scale}")
    ResponseEntity<String> getIco(@PathVariable("volume")int boardGroupId, @PathVariable("scale")String scale);
    
    //3:所有的版块组
    @GetMapping("/all")
    List<BoardGroupVo> getAllUsed();
    
    //4:所有的版块组,级联加载版块组下的版块
    @GetMapping("/all/cascade/{defed}")
    List<BoardGroupCollectVo> getAllCascadeUsedBoard(@PathVariable("defed")int containsDefault);
    
    //5:指定的版块组,级联加载版块组下的版块
    @GetMapping("/{volume}/cascade")
    ResponseEntity<BoardGroupCollectVo> getCascadeUsedBoard(@PathVariable("volume")int boardGroupId);
    
    
    @Component
    static class BoardGroupFallbackFactory implements FallbackFactory<BoardGroupClientFallback> {
        @Override
        public BoardGroupClientFallback create(Throwable cause) {
            return new BoardGroupClientFallback();
        }
    }
    static class BoardGroupClientFallback implements BoardGroupClient{
        
        @Override
        public ResponseEntity<BoardGroupVo> get(int boardGroupId) {
            return ResponseEntity.notFound().build();
        }

        @Override
        public ResponseEntity<String> getIco(int boardGroupId, String scale) {
            return ResponseEntity.notFound().build();
        }

        @Override
        public List<BoardGroupVo> getAllUsed() {
            return Collections.emptyList();
        }

        @Override
        public List<BoardGroupCollectVo> getAllCascadeUsedBoard(int containsDefault) {
            return Collections.emptyList();
        }

        @Override
        public ResponseEntity<BoardGroupCollectVo> getCascadeUsedBoard(int boardGroupId) {
            return ResponseEntity.notFound().build();
        }
    }
}